from time import sleep

from appium.webdriver.common.appiumby import AppiumBy

from appium_qiyeweixin.page_object.personal_information_page import PersonalInformationPage
from appium_qiyeweixin.page_object.public.nav_menu import NavMenu


class AddressBookPage(NavMenu):

    __ADD_MEMBER = (AppiumBy.XPATH, "//*[@text='添加成员']")

    # 添加成员
    def add_member(self):
        element = self.do_swipe(self.__ADD_MEMBER)
        element.click()

        from appium_qiyeweixin.page_object.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)

    # 确认添加是否成功
    def confirm_to_add(self, user_info: dict):
        name = user_info.get("name")
        element = self.do_find((AppiumBy.XPATH, f"//*[@text='{name}']"))

        return element

    # 进入成员详情
    def switch_personal_information(self, user_name: str):
        self.do_ele_click((AppiumBy.XPATH, f"//*[@text='{user_name}']"))

        return PersonalInformationPage(self.driver)

    # 确认是否删除成员
    def confirm_to_del_member(self, user_name: str):
        sleep(2)
        elements = self.do_finds((AppiumBy.XPATH, f"//*[@text='{user_name}']"))

        return elements
